//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    currentTab: 0,
    stars: [0, 1, 2, 3, 4],
    normalSrc: '../../images/normal.png',
    selectedSrc: '../../images/selected.png',
    txt: [],
    cintx: [],
    mobile: [],
    rqkey: [],//评分
    kbkey: [],
    sellerInfo: '宁波乐玛摄影工作室',
    num1: '156',
    num2: '4',
    num3: '3',
    num4: '4',
    src: '../../images/banner.jpg',
    infoTxtarea: '“在这里非常感谢我的摄影师王聪老师和化妆师星子老师很专业，拍摄当天的照片没有修图我就很满意 妆容也是我喜欢的简约”',
    newkb: [],
    showModal: true,



  },
  gogogo: function () {
    wx.navigateTo({
      url: '../search/index',
    })

  },
  savetell: function (e) {
    var that = this;
    var tellp = e.detail.value;

    console.log(e)
    that.setData({ mobile: tellp })
  },
  tianjia: function (e) {
    var that = this;
    var inp = e.detail.value;


    that.setData({ cintx: inp })

    var inputCode = that.data.cintx;

    if (inputCode.length <= 0) {
      wx.showToast({
        title: '请输入验证码',
        icon: 'fail',
        duration: 2000
      })
    } else if (inputCode != that.data.txt) {
      wx.showToast({
        title: '输入验证码错误',
        icon: 'fail',
        duration: 2000
      })
      that.createCode();//刷新验证码  
    } else {
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000,

      })
      var openid = app.globalData.openid;
      var id = that.data.id;
      console.log(that.data)
      var mobile = that.data.mobile;
      console.log(6666666)
      console.log(openid)
      console.log(id)
      console.log(mobile)
      wx.request({
        url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=appointment',
        data: { object_id: id, mobile: mobile, opentionid: openid },
        method: 'post',

        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },

        success(res) {
          console.log(res)
        }


      })
      that.setData({
        showModal: false
      })
    }
  },
  onCancel: function () {
    var that = this;
    that.setData({
      showModal: false,
    })
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  /**
   * 对话框确认按钮点击事件
   */
  onConfirm: function () {
    var that = this;
    that.setData({
      showModal: false,
    })
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  createCode: function () {
    var that = this;
    var code = "";
    var codeLength = 6;//验证码的长度  

    var selectChar = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];//所有候选组成验证码的字符，当然也可以用中文的  

    for (var i = 0; i < codeLength; i++) {
      var charIndex = Math.floor(Math.random() * 36);
      console.log(charIndex)
      code += selectChar[charIndex];
    }
    //alert(code);
    that.setData({ txt: code })
  },
  getnewkb: function () {
    var that = this;
    var newkb = [];
    wx.request({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=get_new_assess',
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        that.setData({
          newkb: res.data
        })
        console.log(that.data.newkb)
      }
    })

  },

  getrqlist: function () {
    var that = this;
    var rqinfoList = [];
    var rqkey = [];
    console.log(111)
    console.log(app.globalData.openid);
    wx.request({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=Ranking&status=1',
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log(res)
        rqinfoList = res.data;
        for (var i in rqinfoList) {
          rqkey[i] = rqinfoList[i].k_info.avg;
        }
        that.setData({
          rqinfoList: rqinfoList,
          rqkey: rqkey
        })
        console.log("rq")
        console.log(that.data.rqkey)
      }
    })
  },
  getkblist: function () {
    var that = this;
    var kbinfoList = [];
    var kbkey = [];
    console.log(111)
    console.log(app.globalData.openid);
    wx.request({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=Ranking&status=2',
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log(res)
        kbinfoList = res.data;
        for (var i in kbinfoList) {
          kbkey[i] = kbinfoList[i].k_info.avg;
        }
        that.setData({
          kbinfoList: kbinfoList,
          kbkey: kbkey
        })
        console.log("kb")
        console.log(that.data.kbkey)
      }
    })
  },

  tabswiper: function (e) {
    var that = this;
    console.log(e)
    if (e.target.dataset.current === that.data.currentTab)
      return false;
    else
      that.setData({ currentTab: e.target.dataset.current })

  },

  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({

    })
  },

  onLoad: function () {
    app.getopenid();
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })
    that.getrqlist();
    that.getkblist();
    that.getnewkb();
    that.createCode();
  }
})




